package com.ruoyi.web.controller.xxc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.news.domain.XxcWallet;
import com.ruoyi.news.service.IXxcWalletService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小程序-钱包Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/xxc/wallet")
public class XxcWalletController extends BaseController
{
    @Autowired
    private IXxcWalletService xxcWalletService;

    /**
     * 查询小程序-钱包列表
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(XxcWallet xxcWallet)
    {
        startPage();
        List<XxcWallet> list = xxcWalletService.selectXxcWalletList(xxcWallet);
        return getDataTable(list);
    }

    /**
     * 导出小程序-钱包列表
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:export')")
    @Log(title = "小程序-钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XxcWallet xxcWallet)
    {
        List<XxcWallet> list = xxcWalletService.selectXxcWalletList(xxcWallet);
        ExcelUtil<XxcWallet> util = new ExcelUtil<XxcWallet>(XxcWallet.class);
        util.exportExcel(response, list, "小程序-钱包数据");
    }

    /**
     * 获取小程序-钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(xxcWalletService.selectXxcWalletById(id));
    }

    @PreAuthorize("@ss.hasPermi('system:wallet:query')")
    @GetMapping(value = "/info/{userId}")
    public AjaxResult infoByUserId (@PathVariable("userId") String userId)
    {
        return success(xxcWalletService.selectXxcWalletByUserId(userId));
    }

    /**
     * 新增小程序-钱包
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:add')")
    @Log(title = "小程序-钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XxcWallet xxcWallet)
    {
        return toAjax(xxcWalletService.insertXxcWallet(xxcWallet));
    }

    @PostMapping("/editInfo")
    public AjaxResult editInfo(@RequestBody XxcWallet xxcWallet)
    {
        return toAjax(xxcWalletService.updateXxcWallet(xxcWallet));
    }

    /**
     * 修改小程序-钱包
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:edit')")
    @Log(title = "小程序-钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XxcWallet xxcWallet)
    {
        return toAjax(xxcWalletService.updateXxcWallet(xxcWallet));
    }

    /**
     * 删除小程序-钱包
     */
    @PreAuthorize("@ss.hasPermi('system:wallet:remove')")
    @Log(title = "小程序-钱包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(xxcWalletService.deleteXxcWalletByIds(ids));
    }
}
